please dont rip this site

The basics - what goes into an applet

import java.awt.*;
import java.applet.*;

public class SimpleApplet extends Applet
{
	public void init()
	{
	}

	public void paint( Graphics g)
	{
	}

	public void destroy()
	{
	}
}
there are three basic methods that should be provided
public void init()
called when the applet is created, this is where any code to build a user interface should be placed.

public void paint( Graphics g)
the appearance of the applet.

public void destroy()
if anything needs to be done when the applet terminates, this is where it should be done. On the whole this isnt that important as when the applet goes, the garbage collector will clear up any memory that it owned


how to add an applet to a HTML page

once the soure for the applet has been compiled it can be embedded into a html page by using the <APPLET> tag:

<APPLET CODE=applet.class WIDTH=width HEIGHT=height>
<PARAM NAME=name1 VALUE=value1>
<PARAM NAME=name2 VALUE=value2>
<PARAM NAME=name3 VALUE=value3>
...
</APPLET>

However many sites disable java at the firewall so your applet may not appear to work in these cases. Most firewalls prevent java files from getting past them by looking for a ".class" extension. Both Netscape and Microsoft provide mechanisms to get around this.

Netscape Navigator

Internet Explorer
Microsoft's Internet explorer does not support the archive attribute of the <APPLET> tag. It uses CAB (Cabinet)


<PARAM>

The <PARAM> provides parameters that the applet should read in its init() method.

These generally control the applet's appearance and are not designed to be substitutes for a user interface.

public void init()
{
  String my_arg1, myarg2, my_arg3, ...;

  my_arg1 = getParameter("name1");
  my_arg2 = getParameter("name2");
  my_arg3 = getParameter("name3");
  ...
}


Converting parameters

public void init() {
  int value = default;

  my_arg =	getParameter("name1");
  if (my_arg == null){
	 try{
		value = Integer.parseInt(my_arg);
	 }
	 catch (NumberFormatException e) {
		value = default;
	 }
  }
}
The arguments are all passed as strings. If they need to be converted there should be adequate error handling to use default values if the conversion fails.

file: /Techref/language/java/nosugar/basics/index.htm, 5KB, , updated: 1997/1/28 16:19, local time: 2024/12/27 21:24,
TOP NEW HELP FIND: 
3.144.224.30:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://linistepper.com/techref/language/java/nosugar/basics/index.htm"> Learning Java [basics]</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?